package com.anchovy.maven.controller;


import com.anchovy.maven.entity.User;
import com.anchovy.maven.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@RefreshScope
public class UserController {
    @Autowired
    private UserService userService;

    //    @Value("${id}")
    private Integer id = 0;


    /**
     * 根据ID查找用户
     *
     * @param id 用户ID
     * @return 找到的用户对象
     */
    @GetMapping("/findUserById")
    public User findUserById(Integer id) {
        return userService.findUserById(id);
    }


    @GetMapping("/getId")
    public Integer getId() {
        return this.id;
    }


    /**
     * 保存用户信息
     *
     * @param user 用户对象
     * @return 保存后的用户对象
     */
    @PostMapping("/saveUser")
    public User saveUser(User user) {
        userService.saveUser(user);
        return user;
    }


}
